package pheromoneMap;

import java.util.Iterator;
import java.util.Vector;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;

public class MapVisualization extends JFrame implements ActionListener {
	static final long serialVersionUID = 1;
	
	Vector<JButton> m_buttons;
	PheromoneCanvas m_canvas;
	
	public MapVisualization( PheromoneMap parent ) {
		super( "Pheromone Visualization" );
		
		setDefaultCloseOperation( EXIT_ON_CLOSE );

		

		setSize( 800, 800 );
		Container content = this.getContentPane();
		content.setBackground( Color.white );
		content.setLayout( new FlowLayout() );

		m_buttons = new Vector<JButton>();
		for (PheromoneType type : PheromoneType.values()) {
			JButton button = new JButton( type.toString() );
			button.addActionListener(this);
			if( type == PheromoneType.TO_HOME )
				button.setEnabled( false );
			content.add(button);
			m_buttons.add(button);
		}

		m_canvas = new PheromoneCanvas( parent );
		m_canvas.setPreferredSize( new Dimension( parent.m_mapWidth * PheromoneCanvas.blockSize,
				parent.m_mapHeight * PheromoneCanvas.blockSize ) );
		JScrollPane scrollPane = new JScrollPane( m_canvas );
		scrollPane.setPreferredSize( new Dimension( 700, 700 ) );
		content.add( scrollPane );
	}

	public void actionPerformed(ActionEvent event) {
		PheromoneCanvas.pheromoneTypeToVisualize(
				PheromoneType.pheromoneTypeFromString(
						event.getActionCommand()));
		
		for( JButton button : m_buttons ) {
			button.setEnabled( true );
		}
		JButton clickedButton = (JButton) event.getSource();
		clickedButton.setEnabled( false );
	}
}
